package edu.washington.ling.syntric.io;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;

public class ExampleDocWriterSGML extends ExampleDocWriter {
	private String path;
	private PrintWriter pWriter;
	
	public ExampleDocWriterSGML(String path) throws IOException {
		super(path);
		pWriter = new PrintWriter(new FileWriter(new File(path)));
	}
	public static ExampleDocWriterSGML newWriter(String path) throws IOException {
		return new ExampleDocWriterSGML(path);
	}
	public void close(){
		pWriter.flush();
		pWriter.close();
	}
	public String getPath() {
		return path;
	}
	public void println(String line) {
		pWriter.println(line);
	}
	@Override
	public void writeExample(Example exr, String[] includeLayers) {
		writeExample(exr);
	}
	@Override
	public void writeExample(Example exr) {
		pWriter.println(String.format("<Sentence id=\"%s\">", exr.getID()));
		pWriter.println(String.format("<Original>%s</Original>", exr.hasOriginal() ? exr.getOriginal() : ""));
		pWriter.println(String.format("<Gloss>%s</Gloss>", exr.hasGloss() ? exr.getGloss() : ""));
		pWriter.println(String.format("<Translation>%s</Translation>", exr.hasTranslation() ? exr.getTranslation() : ""));
		pWriter.println("</Sentence>\n");
		
	}
}
